package algorithm.easy;

/**
 * @author 江岸
 * @version V1.0
 * @ClassName: GuessNumber374
 * @description:
 *  * Forward declaration of guess API.
 *  * @param  num   your guess
 *  * @return 	     -1 if num is lower than the guess number
 *  *			      1 if num is higher than the guess number
 *  *               otherwise return 0
 *  * int guess(int num);
 * @date 2020/8/2814:31
 * @since V1.0
 */
public class GuessNumber374 {
    public int guessNumber(int n) {
            int min = 1;
            int max = n;
            int mid=0;
            while (true){
                mid = min+(max-min)/2;
                if (guess(mid)==0){
                    break;
                }
                if (guess(mid)==1){
                    min = mid+1;
                }else {
                    max = mid-1;
                }
            }
            return mid;
        }
    //无用代码避免报错
    int guess(int n){return 1;}
}
